//
//  CNSearchViewModel.m
//  BeeQuick_19
//
//  Created by whong7 on 16/9/23.
//  Copyright © 2016年 CN Team. All rights reserved.
//

#import "CNSearchViewModel.h"
#import "CNSearchModel.h"
@implementation CNSearchViewModel

+(void)loadDataWithBlock:(void(^)(NSArray *dataArray)) searchBlock;
{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    
    [param setValue:@"8" forKey:@"call"];
    
    [[CNHTTPSessionManager sharedManager] request:CNHttpMethodPost componentUrlString:@"http://iosapi.itcast.cn/loveBeen/promotion.json.php" parameters:param completion:^(id response, NSError *error) {
        
        if (response) {
            NSLog(@"%@",[response valueForKey:@"data"]);
            NSArray *array = [NSArray yy_modelArrayWithClass:[CNSearchModel class] json:[response valueForKey:@"data"]];
            
            //数据库后的array
            NSArray *completeArray = [[SQLiteManager sharedSQLiteManager] getValueWith:array];
            
            searchBlock(completeArray);
            
        }
        else
        {
            NSLog(@"%@",error);
            
        }
    }];
}


@end
